package com.xszx.servlet.admin.shop;

import com.xszx.dao.GoodsDao;
import com.xszx.dao.impl.GoodsDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/UpdateGoodsStateServlet")
public class UpdateGoodsStateServlet extends HttpServlet {
    static GoodsDao goodsDao = new GoodsDaoImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");

        Integer id = Integer.parseInt(req.getParameter("id"));
        Integer goodsState = Integer.parseInt(req.getParameter("goodsState"));

        goodsDao.updateGoodsState(id, goodsState);
        resp.sendRedirect("GetAllGoodsServlet");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
